import pdfplumber
import re
with pdfplumber.open("path_to_pdf/Annual_Report_2023.pdf") as pdf:
    all_text = ''
    for page in pdf.pages:
        all_text += page.extract_text() + '\n'
        import pdfplumber
import re

# 打开PDF文件
with pdfplumber.open("path_to_pdf/Annual_Report_2023.pdf") as pdf:
    text = ''
    for page in pdf.pages:
        # 提取页面文本
        page_text = page.extract_text()
        if page_text:
            text += page_text + '\n'

# 去除页眉页脚
text = re.sub(r'\d{1,2}/\d{1,2}/\d{4}', '', text)  # 假设页眉页脚包含日期格式YYYY/MM/DD
text = re.sub(r'Page \d+', '', text)  # 假设页脚包含页码

# 打印提取的文本
print(text)
revenue_2023 = 1106867  # 2023年营收
revenue_2022 = 956209   # 2022年营收
net_income_2023 = -15437  # 2023年净利润
total_assets_2023 = 865946  # 2023年总资产
total_liabilities_2023 = 599660  # 2023年总负债
total_equity_2023 = 222528  # 2023年股东权益

# 计算营收增长率
revenue_growth_rate = (revenue_2023 - revenue_2022) / abs(revenue_2022)

# 计算净利润率
net_profit_margin = (net_income_2023 / revenue_2023) * 100

# 计算资产负债率
debt_to_asset_ratio = total_liabilities_2023 / total_assets_2023

# 计算净资产收益率
# 假设平均股东权益为2022年和2023年的平均值
average_equity = ((total_equity_2023 + 270422) / 2)  # 2022年股东权益为270422
return_on_equity = (net_income_2023 / average_equity) * 100

# 打印结果
print(f"营收增长率: {revenue_growth_rate:.2%}")
print(f"净利润率: {net_profit_margin:.2%}")
print(f"资产负债率: {debt_to_asset_ratio:.2%}")
print(f"净资产收益率: {return_on_equity:.2%}")
pip install matplotlib pandas tabulate
import pandas as pd
import matplotlib.pyplot as plt
from tabulate import tabulate
data = {
    "Year": ["2021", "2022", "2023"],
    "Revenue": [760192, 956209, 1106867],
    "Net Income": [29292, 18119, -15437],
    "Total Assets": [851342, 880841, 865946],
    "Total Liabilities": [595472, 595472, 599660]
}

# 转换为DataFrame
df = pd.DataFrame(data)

# 营收变化趋势图
plt.figure(figsize=(10, 5))
plt.plot(df["Year"], df["Revenue"], marker='o')
plt.title("Revenue Trend")
plt.xlabel("Year")
plt.ylabel("Revenue ($)")
plt.grid(True)
plt.show()

# 净利润变化趋势图
plt.figure(figsize=(10, 5))
plt.plot(df["Year"], df["Net Income"], marker='o')
plt.title("Net Income Trend")
plt.xlabel("Year")
plt.ylabel("Net Income ($)")
plt.grid(True)
plt.show()

# 资产总额变化趋势图
plt.figure(figsize=(10, 5))
plt.plot(df["Year"], df["Total Assets"], marker='o')
plt.title("Total Assets Trend")
plt.xlabel("Year")
plt.ylabel("Total Assets ($)")
plt.grid(True)
plt.show()

# 负债总额变化趋势图
plt.figure(figsize=(10, 5))
plt.plot(df["Year"], df["Total Liabilities"], marker='o')
plt.title("Total Liabilities Trend")
plt.xlabel("Year")
plt.ylabel("Total Liabilities ($)")
plt.grid(True)
plt.show()

# 创建表格对比公司与同行业公司的关键指标
同行公司数据 = {
    "指标": ["市值", "营收增长率", "净利润", "资产总额", "负债总额"],
    "Entravision Communications": ["$304,852,197", "16%", "-$15,437", "$865,946", "$599,660"],
    "同行业公司A": ["$500,000,000", "10%", "$50,000,000", "$1,200,000,000", ""],
    "同行业公司B": ["$750,000,000", "20%", "$30,000,000", "$900,000,000", ""]
}

df_peers = pd.DataFrame(同行公司数据)
print(tabulate(df_peers, headers='keys', tablefmt='psql'))
